#ifndef __MC31xx_HAL_UART_H
#define __MC31xx_HAL_UART_H

#include "mc31xx_hal_def.h"

//串口初始化结构体
typedef struct
{
    uint32_t ClockDivision;             //时钟分频
    uint32_t BaudRate;                  //波特率
    uint32_t WordLength;                //数据位8 不支持修改
    uint32_t StopBits;                  //停止位1 不支持修改
    uint32_t Parity;                    //校验位无 不支持修改
    uint32_t PinTxd;                    //发送引脚
    uint32_t PinRxd;                    //接收引脚
}UART_InitTypeDef;

//串口句柄
typedef struct
{
    GPCOM_TypeDef           *Instance;      //寄存器基址
    UART_InitTypeDef        Init;           //初始化结构体
    uint8_t                RxFifoPoint;     //读缓冲写指针
}UART_HandleTypeDef;



HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
HAL_StatusTypeDef HAL_UART_SetSpeed(UART_HandleTypeDef *huart,uint32_t BaudRate);

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
uint16_t HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);


#define IS_UART_INSTANCE(INSTANCE) (((INSTANCE) == GPCOM0) || \
                                    ((INSTANCE) == GPCOM1) || \
                                    ((INSTANCE) == GPCOM2) || \
                                    ((INSTANCE) == GPCOM3) || \
                                    ((INSTANCE) == GPCOM4) || \
                                    ((INSTANCE) == GPCOM5) || \
                                    ((INSTANCE) == GPCOM6) || \
                                    ((INSTANCE) == GPCOM7) || \
                                    ((INSTANCE) == GPCOM8) || \
                                    ((INSTANCE) == GPCOM9) || \
                                    ((INSTANCE) == GPCOM10) || \
                                    ((INSTANCE) == GPCOM11))

#endif
